<title>渠道商供应通道</title>
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>渠道商供应通道管理</cite></a>
    <a><cite>所有渠道商供应通道</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <!--<div class="layui-tab layui-tab-brief">-->
    <!--<ul class="layui-tab-title">-->
    <!--<li class="layui-this">渠道商列表</li>-->
    <!--</ul>-->

    <div class="layui-tab-content">

      <div class="layui-btn-group demoTable lay-mb15">
        <!--<div class="layui-form" style="float:right;">-->
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
          <div class="layui-form-item" style="margin:0;">
            <!--<div class="layui-input-inline">-->
            <!--<label class="layui-form-label">商户ID</label>-->
            <!--<div class="layui-input-block">-->
            <!--<input type="text" name="mchId" id="mchId" placeholder="请输入商户ID" autocomplete="off" class="layui-input">-->
            <!--</div>-->
            <!--</div>-->
            <div class="layui-inline">

              <label class="layui-form-label">渠道商ID</label>
              <div class="layui-input-block">
                <input type="text" name="channelMchId" id="channelMchId" placeholder="请输入渠道商ID" autocomplete="off" class="layui-input">
              </div>
            </div>

            <div class="layui-inline">
              <!--<button id="search" class="layui-btn  layuiadmin-btn-admin" data-type="reload"><i class="layui-icon layui-icon-search"></i></button>-->
              <button id="search" class="layui-btn layuiadmin-btn-admin" data-type="reload">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
              </button>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button id="addChannelAgentMch" class="layui-btn layui-btn-normal" data-type="add"><i class="layui-icon"></i>添加
          </button>
          <button id= "output" class="layui-btn layui-btn-warm" data-type="output"><i class="layui-icon layui-icon-download-circle"></i>导出
          </button>
          <button id= "batchdel" class="layui-btn layui-btn-danger" data-type="batchdel"><i class="layui-icon"></i>删除
          </button>
        </div>

        <!--<div class="layui-row">-->
        <!--<div class="layui-form-item">-->
        <!--<blockquote class="layui-elem-quote" id="amountTip"></blockquote>-->
        <!--</div>-->
        <!--</div>-->
        <table id="ChannelMchSupply_dataAll" lay-filter="ChannelMchSupply_dataAll"></table>
      </div>
    </div>
  </div>

</div>
<style>
  .viewInfo {
    padding: 30px;
    font-size: 14px;
    color: #666;
  }

  .viewInfo li {
    margin-bottom: 15px;
  }

  .viewInfo li span {
    display: inline-block;
    width: 25%;
    text-align: right;
    margin-right: 30px;
    font-weight: bold;
  }


</style>
<script>
    layui.use(['admin', 'table', 'util'], function(){
//
        var $ = layui.$
            ,admin = layui.admin
            ,table = layui.table
            ,element = layui.element
            ,form = layui.form;

        element.render('breadcrumb', 'breadcrumb');

        var tplStatus = function(d){
            if(d.status == 1) {
                return '  <input type="checkbox" name="status" lay-filter="layTableSwitchForMsupply" lay-skin="switch" lay-text="开|关" checked="true"> <div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>开</em> <i></i></div>';
            }
            return ' <input type="checkbox" name="status" lay-filter="layTableSwitchForMsupply" lay-skin="switch" lay-text="开|关" > <div class="layui-unselect layui-form-switch" lay-skin="_switch"><em>关</em><i></i></div>';

        };

        //商户列表
        table.render({
            elem: '#ChannelMchSupply_dataAll'
            ,url: layui.setter.baseUrl + '/channelmch_passage/list' //列表接口
            ,where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            ,id: 'tableReload'
            ,page: true
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id', fixed: 'left',title: '编号'}
                ,{field: 'channelMchId',title: '渠道商ID'}
                ,{field: 'paypassage', title: '支付通道ID'}
                ,{field: 'passageName', title: '支付通道名称'}
                ,{field: 'payProductId', title: '支付产品ID'}
                ,{field: 'productName', title: '支付产品名称'}
                ,{field: 'status', title: '状态', width: 80,templet: tplStatus}
                ,{field: 'channelMchRate', title: '通道费率'}
            ]]
            ,skin: 'line'
        });

        form.on("switch(layTableSwitchForMsupply)",function(data){
            //  layer.msg(this.checked ? "true" : "false");
            var index_sms;
            // 获取当前控件
            var selectIfKey=data.othis;
            // 获取当前所在行
            var parentTr = selectIfKey.parents("tr");
            // 获取当前所在行的索引
            var parentTrIndex = parentTr.attr("data-index");
            var id=parentTr.find(('td:eq(1)')).text().trim();
            admin.req({
                type: 'get',
                url: layui.setter.baseUrl + '/channelmch_passage/updateStatus',
                data: {
                    id : id,
                    status : this.checked ? "true" : "false"
                },
                beforeSend:function(){
                    index_sms = layer.msg('正在切换中，请稍候',{icon: 16,time:false,shade:0.8});
                },
                error: function(err){
                    layer.alert(JSON.stringify(err.field), {
                        title: '错误提示'
                    })
                },
                success: function(res){
                    if(res.code == 0){
                        layer.close(index_sms);
                        layer.msg('修改渠道商通道状态成功', {icon: 6});
                    }
                }
            });
            //       layer.msg(this.checked ? "true" : "false");

            // layer.msg( data.channelMchId);
        })
        // 搜索
//    var $ = layui.$, active = {
//      reload: function(){
//          alert(1);
//        var channelMchId = $('#channelMchId').val();
//        //执行重载
//        table.reload('tableReload', {
//          page: {
//            curr: 1 //重新从第 1 页开始
//          }
//          ,where: {
//                channelMchId: channelMchId
//          }
//        });
//      }
//    };
        $('#search').on('click', function() {

            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('#addChannelAgentMch').on('click', function() {

            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('#batchdel').on('click', function() {

            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                var channelMchId = $('#channelMchId').val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        channelMchId: channelMchId
                    }
                });
            },
            batchdel: function(){
                var checkStatus = table.checkStatus('tableReload')
                    ,checkData = checkStatus.data; //得到选中的数据
                if(checkData.length === 0){
                    return layer.msg('请选择数据');
                }
                layer.confirm('确定删除选中的渠道商供应通道吗？', function(){
                    var ids = "";
                    $.each(checkData, function(i, n){
                        ids = ids + "," + n.id;
                    });
                    if(ids != "") {
                        ids = ids.substring(1);
                    }
                    admin.req({
                        type: 'get',
                        url: layui.setter.baseUrl + '/channelmch_passage/delete',
                        data: {
                            ids: ids,
                        },
                        success: function(res){
                            if(res.code == 0) {
                                layer.msg('删除成功', {
                                    icon: 1
                                });
                                table.reload("tableReload");
                            }
                        }
                    });
                });
            },
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('tableReload')
                    , data = checkStatus.data;
                active.getId(data)

                layer.alert(JSON.stringify(data));
            }
            , getId: function (data) {
                var idArr = [];
                for (var i = 0; i < data.length; i++) {
                    console.log(data[i].id)
                    idArr.push(data[i].id)
                }
                console.log(idArr)
            }
            , getCheckLength: function () { //获取选中数目
                var checkStatus = table.checkStatus('tableReload')
                    , data = checkStatus.data;
                layer.msg('选中了：' + data.length + ' 个');
            }
            , isAll: function () { //验证是否全选
                var checkStatus = table.checkStatus('tableReload');
                layer.msg(checkStatus.isAll ? '全选' : '未全选')
            }
            , add: function() { // 增加一条列表
                layer.open({
                    title: '新增渠道商供应通道',
                    type: 2,
                    //skin: 'layui-layer-rim',
                    shadeClose: false,
                    area: admin.screen() < 2 ? ['80%', '300px'] : ['800px', '600px'],
                    content: layui.setter.base + 'views/channelmch/channelmchSupply/channelmchSupply_add.html'
                });
            }
        };
        // 渲染表单
        form.render();
    });
</script>